package com.why.jvm.hotspot.src.share.vm.oops;

import com.why.jvm.hotspot.src.share.vm.oops.constants.ConstantUtf8Info;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

/**
 * @author xiaoTian
 * @date 2022/7/16
 * @Description:
 */

@Data
public class MethodInfo {

    private ConstantPool constantPool;

    private int accessFlags;

    private int nameIndex;

    private int descriptorIndex;

    private int attributesCount;

    private List<AttributeInfo> attributeInfos = new ArrayList<>();

    public String getDescriptor(){
        return ((ConstantUtf8Info) constantPool.getConstantPoolMap().get(descriptorIndex)).getValue();
    }

    @Override
    public String toString() {
        StringBuffer s = new StringBuffer( "\tMethodInfo{" +
                "\n\taccessFlags=" + accessFlags +
                ", \n\tnameIndex=" + nameIndex +
                ", \n\tdescriptorIndex=" + descriptorIndex +
                ", \n\tdescriptor=" +  getDescriptor() +
                ", \n\tattributesCount=" + attributesCount);
        getAttributeInfos().forEach(e->s.append("\t"+e.toString()+"\n"));
        s.append('}');
        return s.toString();
    }
}
